<template>
  <div class="init_main">
    <!-- <p class="name_sty">{{ name }}</p> -->
    <div class="query">
      关键字：<el-input
        size="mini"
        style="width: 200px"
        v-model="query.Name"
      ></el-input>
      资源状态：
      <el-select v-model="query.Status" placeholder="" size="mini">
        <el-option label="全部" :value="-1"> </el-option>
        <el-option label="未审核" :value="0"> </el-option>
        <el-option label="已审核" :value="1"> </el-option>
      </el-select>
      <el-button
        plain
        size="mini"
        icon="el-icon-search"
        style="margin-left: 10px"
        @click="getList"
        >查询</el-button
      >
      <!-- <el-button
        plain
        size="mini"
        icon="el-icon-plus"
        type="primary"
        @click="open_dialog('新增')"
        >新增</el-button
      >
      <el-button
        plain
        size="mini"
        icon="el-icon-edit"
        type="primary"
        @click="open_dialog('修改')"
        >修改</el-button
      >
      <el-button
        plain
        size="mini"
        icon="el-icon-delete"
        type="danger"
        @click="del_row"
        >删除</el-button
      > -->
    </div>
    <div class="table">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        height="600"
        highlight-current-row
        @current-change="row_click"
      >
        <el-table-column
          prop="DBId"
          label="数据库名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="ViewName"
          label="数据视图名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Name"
          label="描述"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Count"
          label="数据量"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="Status"
          label="状态"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="CreateTime"
          label="创建时间"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="CreateUser"
          label="创建人"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="UpdateTime"
          label="修改时间"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="UpdateUser"
          label="修改人"
          align="center"
        ></el-table-column>
      </el-table>
    </div>
    <div class="page">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange_page"
        :current-page="query.page"
        :page-sizes="[10, 15, 50, 100]"
        :page-size="query.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="query.total"
      >
      </el-pagination>
    </div>
    <!-- 弹层 -->
    <el-dialog
      :title="dialog_title"
      :visible.sync="dialogVisible"
      width="45%"
      :before-close="handleClose"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <table border="1" style="width: 100%" v-if="dialogVisible">
        <tr>
          <td class="tac">设备名称：</td>
          <td><el-input size="mini" v-model="form.devicename"></el-input></td>
        </tr>
        <tr>
          <td class="tac">设备类型：</td>
          <td><el-input size="mini" v-model="form.devicetype"></el-input></td>
        </tr>
        <tr>
          <td class="tac">上线日期：</td>
          <td><el-input size="mini" v-model="form.installdate"></el-input></td>
        </tr>
        <tr>
          <td class="tac">设备IP地址：</td>
          <td><el-input size="mini" v-model="form.ipaddr"></el-input></td>
        </tr>
        <tr>
          <td class="tac">设备物理位置：</td>
          <td><el-input size="mini" v-model="form.location"></el-input></td>
        </tr>
        <tr>
          <td class="tac">设备MAC地址：</td>
          <td><el-input size="mini" v-model="form.macaddr"></el-input></td>
        </tr>
        <tr>
          <td class="tac">制造商名称：</td>
          <td><el-input size="mini" v-model="form.manufacturer"></el-input></td>
        </tr>
        <tr>
          <td class="tac">设备型号：</td>
          <td><el-input size="mini" v-model="form.model"></el-input></td>
        </tr>
        <tr>
          <td class="tac">其他备注信息：</td>
          <td><el-input size="mini" v-model="form.notes"></el-input></td>
        </tr>
        <tr>
          <td class="tac">所属部门：</td>
          <td><el-input size="mini" v-model="form.ownerdept"></el-input></td>
        </tr>
        <tr>
          <td class="tac">设备使用人或负责人姓名：</td>
          <td><el-input size="mini" v-model="form.owneruser"></el-input></td>
        </tr>
        <tr>
          <td class="tac">设备购买日期：</td>
          <td><el-input size="mini" v-model="form.purchasedate"></el-input></td>
        </tr>
        <tr>
          <td class="tac">设备序列号：</td>
          <td><el-input size="mini" v-model="form.serialnumber"></el-input></td>
        </tr>
        <tr>
          <td class="tac">设备当前状态：</td>
          <td><el-input size="mini" v-model="form.status"></el-input></td>
        </tr>
      </table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose" size="mini">关 闭</el-button>
        <el-button type="primary" @click="btn_ok" size="mini">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      query: {
        Name: "",
        page: 1,
        limit: 10,
        total: 0,
        Status: -1,
        orderby: "id",
      },
      tableData: [],
      dialogVisible: false,
      dialog_title: "",
      row_info: null,
      form: {
        Type: "",
        Title: "",
        Content: "",
        Image: "",
      },
      userList: [],
    };
  },
  mounted() {
    this.name = this.$route.meta.title;
    // this.getUserList();
    this.getList();
  },
  methods: {
    getList() {
      this.$post("/ServiceManage/Service/ViewList", this.query).then((res) => {
        this.tableData = res.data.list;
        this.query.total = res.data.TotalCount;
      });
    },
    getUserList() {
      this.$post("/Bs/GetAllUserList").then((res) => {
        this.userList = res.Data;
      });
    },
    open_windo(url) {
      window.open(url);
    },
    row_click(row) {
      if (!row) {
        this.row_info = null;
        return;
      }
      this.row_info = row;
    },
    del_row() {
      this.$deleteF("/Platform/Deviceinfo/Delete?id=" + this.row_info.id).then(
        (res) => {
          this.getList();
        }
      );
    },
    handleClose() {
      this.form = { Users: [] };
      this.dialogVisible = false;
    },
    btn_ok() {
      // this.form
      var url = this.form.id
        ? "/Platform/Deviceinfo/Update"
        : "/Platform/Deviceinfo/Create";
      if (this.form.id) {
        this.$put(url, this.form).then((res) => {
          this.getList();
          this.handleClose();
        });
      } else {
        this.$post(url, this.form).then((res) => {
          this.getList();
          this.handleClose();
        });
      }
    },
    open_dialog(val) {
      this.dialog_title = val + "设备信息";
      if (val == "新增") {
        this.dialogVisible = true;
        return;
      }
      if (val == "修改" && this.row_info) {
        this.form = this.row_info;
        this.dialogVisible = true;
        return;
        // this.$get("/Option/GetOneNew/" + this.row_info.Id).then((res) => {
        //   this.form = res.Data;
        //   this.dialogVisible = true;
        //   return;
        // });
      } else {
        this.$notify.error({
          title: "错误",
          message: "请选择一条数据后操作！",
        });
        return;
      }
    },
    handleSizeChange(val) {
      this.query.limit = val;
      this.query.page = 1;
    },
    handleCurrentChange_page(val) {
      this.query.page = val;
      this.getList();
    },
    setUserName(id) {
      console.log(id);
    },
  },
};
</script>

<style scoped lang='scss'>
.init_main {
  background-color: #fff;
  height: calc(100vh - 60px);
  border: 1px solid #333;
  border-radius: 5px;
  margin: 5px;
  padding: 10px;
  font-family: "FangSong";
  color: #000;
  .name_sty {
    color: #000;
    font-weight: 700;
    font-size: 18px;
    font-family: "FangSong";
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
  }
  .table {
    margin-top: 15px;
  }
  .page {
    text-align: right;
  }
}
::v-deep .el-table__body tr.current-row > td.el-table__cell {
  background-color: rgb(208, 229, 250);
  color: rgb(65, 158, 255);
  font-weight: 700;
}
.tac {
  text-align: center;
}
</style>